package pl.mmadej.ds4java.ds.tree.twothree;

import pl.mmadej.ds4java.ds.list.ArrayList;
import pl.mmadej.ds4java.ds.list.List;

class MultiValueNode<T extends Comparable<T>> {

    private List<MultiValueNode<T>> children = new ArrayList<MultiValueNode<T>>(4);
    private List<T> values = new ArrayList<T>(3);
    private MultiValueNode<T> parent;

    MultiValueNode(T... values) {
        for (T value : values) {
            this.values.insert(value);
        }
    }

    boolean containsValue(T value) {
        return values.contains(value);
    }

    boolean doesNotContainValue(T value) {
        return !containsValue(value);
    }

    boolean isNotLeaf() {
        return !children.empty();
    }

    List<T> getValues() {
        return values;
    }

    T getValueAt(int index) {
        return values.searchAt(index);
    }

    void insertValueAt(int index, T value) {
        values.insertAt(index, value);
    }

    MultiValueNode<T> getParent() {
        return parent;
    }

    List<MultiValueNode<T>> getChildren() {
        return children;
    }

    int getChildrenCount() {
        return children.size();
    }

    int getValuesCount() {
        return values.size();
    }

    int indexOfChild(MultiValueNode<T> child) {
        return children.indexOf(child);
    }

    MultiValueNode<T> getChildAt(int index) {
        return children.searchAt(index);
    }

    void setParent(MultiValueNode<T> parent) {
        this.parent = parent;
    }

    void insertChild(MultiValueNode<T> child) {
        children.insert(child);
    }

    void deleteChild(MultiValueNode<T> node) {
        children.delete(node);
    }

    void insertChildAt(int index, MultiValueNode<T> child) {
        children.insertAt(index, child);
    }
}
